package com.yanwq.sayhi.rest;

import com.yanwq.sayhi.bean.Club;
import com.yanwq.sayhi.service.ClubService;
import com.yanwq.sayhi.tool.MD5Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 作者：yanweiqiang。
 * 日期：2016/6/16 0016。
 */
@RestController
@RequestMapping(path = "/club")
public class ClubRest {

    @Autowired
    private ClubService service;

    @RequestMapping(path = "/add", method = RequestMethod.POST)
    public Club add(@RequestBody Club club) {
        return service.add(club);
    }

    @RequestMapping(path = "/update", method = RequestMethod.POST)
    public Club update(@RequestBody Club club) {
        club.setPassword(MD5Tool.GetMD5Code(club.getPassword()));
        return service.update(club);
    }

    @RequestMapping(path = "/list", method = RequestMethod.GET)
    public List<Club> list(long userId, int page, int size) {
        return service.listAll(userId, page, size);
    }

    @RequestMapping(path = "/list/name", method = RequestMethod.GET)
    public List<Club> listByName(String name, int page, int size) {
        return service.listByName(name, page, size);
    }

    @RequestMapping(path = "/list/public", method = RequestMethod.GET)
    public List<Club> listPublic(int page, int size) {
        return service.listByPermission(0, page, size);
    }

    @RequestMapping(path = "/list/password", method = RequestMethod.GET)
    public List<Club> listPassword(int page, int size) {
        return service.listByPermission(1, page, size);
    }

    @RequestMapping(path = "/list/id", method = RequestMethod.GET)
    public List<Club> listId(int page, int size) {
        return service.listByPermission(2, page, size);
    }
}
